package com.feiyuan.listener;

import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

/**
 * RabbitMQ消息队列监听
 */
@Component
public class RabbitMQMessageListener {

    @RabbitListener(queues = "TestDirectQueue")
    public void process(Map testMessage) {
        System.out.println("DirectReceiver消费者收到消息  : " + testMessage.toString());
    }


    @RabbitListener(queues = "delay_queue_name")
    public void delayReceive(String msg) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println(sdf.format(new Date()) + " " + msg);
        System.out.println("Receiver：执行取消订单");
    }

    @RabbitListener(queues = "topic.man")
    public void topicManReceiver(Map testMessage) {
        System.out.println("TopicManReceiver消费者收到消息  : " + testMessage.toString());
    }

    @RabbitListener(queues = "topic.woman")
    public void topicTotalReceiver(Map testMessage) {
        System.out.println("TopicTotalReceiver消费者收到消息  : " + testMessage.toString());
    }
}
